import axios from "axios";
import React from "react";
import { useNavigate } from "react-router-dom";
import { Form, Input, Button, Notify } from "react-vant";
const Login = () => {
  const navigate = useNavigate()
  const onFinish = async (values) => {
    const resp = await axios.post("/api/login", values);
    if(resp.data.code === 10000) {
      const userInfo = resp.data.data;
      localStorage.setItem('userInfo', JSON.stringify(userInfo));
      navigate('/')
      Notify.show({ type: 'success', message: resp.data.message })
    } else {
      Notify.show({ type: 'danger', message: resp.data.message })
    }
 
  };
  return (
    <div>
      <Form
        onFinish={onFinish}
        footer={
          <div>
            <Button nativeType="submit">登录</Button>
          </div>
        }
      >
        <Form.Item name="username" label="用户名">
          <Input></Input>
        </Form.Item>
        <Form.Item name="password" label="密码">
          <Input></Input>
        </Form.Item>
      </Form>
    </div>
  );
};

export default Login;
